package com.fly.service.Impl;

import com.fly.bean.Circuitry;
import com.fly.bean.Pole;
import com.fly.mapper.PoleMapperO;
import com.fly.service.PoleServiceO;
import com.fly.util.Page;
import com.fly.vo.AndPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: Orchid
 * @Date: 2019/11/27 20:17
 * @Description:
 */
@Service
public class PoleServiceOImpl implements PoleServiceO {

    @Autowired
    PoleMapperO poleMapperO;

    @Override
    public List<Pole> queryPoleByPage(Page page) {

        List<Pole> poles = poleMapperO.selectPoleByPage(page);

        return poles;
    }

    @Override
    public Integer queryAllPoleCount() {

        Integer count = poleMapperO.selectAllPoleCount();

        return count;
    }

    @Override
    public boolean queryPoleNoIsExit(Pole pole) {

        int is = poleMapperO.selectPoleNoIsExit(pole);

        if (is > 0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public List<Pole> queryPolePageByCirIdAndActivate(AndPageVO andPageVO) {

        Circuitry circuitry = andPageVO.getPole().getCircuitry();

        if (circuitry.getCircuitryName() != null){
            //拼接模糊查询
            circuitry.setCircuitryName("%"+circuitry.getCircuitryName()+"%");
        }

        andPageVO.getPole().setCircuitry(circuitry);

        Pole pole = andPageVO.getPole();

        if (pole.getPoleNo() != null){
            pole.setPoleNo("%" + pole.getPoleNo() +"%" );
        }

        andPageVO.setPole(pole);

        return poleMapperO.selectPolePageByCirIdAndActivate(andPageVO);
    }

    @Override
    public Integer addPole(Pole pole) {

        //添加杆塔
        Integer count = poleMapperO.insertPole(pole);

        return count;
    }

//    @Override
//    public Integer updateActive(Pole pole) {
//
//        Integer isUp = poleMapperO.updateActive(pole);
//
//        return isUp;
//    }

    @Override
    public Integer deleteByPoleId(Integer poleId) {

        return poleMapperO.deleteByPoleId(poleId);
    }

    @Override
    public Integer updatePoleById(Pole pole) {

        return poleMapperO.updatePoleById(pole);
    }

    @Override
    public Integer querySysIdByPoleId(Integer poleId) {

        return poleMapperO.selectSysIdByPoleId(poleId);
    }

    @Override
    public Pole queryPoleByPoleId(Integer poleId) {

        return poleMapperO.selectPoleByPoleId(poleId);
    }

    @Override
    public Boolean queryCountByPoleActiveDisable(String poleNo) {

        Integer count = poleMapperO.selectCountByPoleActiveDisable(poleNo);

        //杆塔状态是停用，返回true
        if (count > 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean queryPoleIsCir(Pole pole) {

        Integer count = poleMapperO.selectPoleIsCir(pole);

        if (count > 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean queryPoleNoOtherIsExit(Pole pole) {

        Integer count = poleMapperO.selectPoleNoOtherIsExit(pole);

        if (count > 0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public Boolean queryPoleIsDamage(Integer poleId) {

        Integer count = poleMapperO.selectPoleIsDamage(poleId);

        if (count > 0){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public Integer queryPoleCirIsNull(Integer poleId) {

        return poleMapperO.selectPoleCirIsNull(poleId);
    }


}
